package com.ctgu.zmc.stresstest.common.utils;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * @author ZMC
 * @description 分页查询结果
 * @date 2022/9/6 14:15
 */
@Data
@NoArgsConstructor
public class PageResult<T> implements Serializable {

    private static final long serialVersionUID = 8623468181983035254L;

    /**
     * 当前页码
     */
    private Long pageNo;

    /**
     * 页面大小
     */
    private Long pageSize;

    /**
     * 总记录数
     */
    private Long totalCount;

    /**
     * 总页数
     */
    private Integer totalPage;

    /**
     * 数据列表
     */
    private List<T> data;

    public PageResult(Page<T> page) {
        this.data = page.getRecords();
        this.pageNo = page.getCurrent();
        this.pageSize = page.getSize();
        this.totalCount = page.getTotal();
        this.totalPage = (int) Math.ceil((double) totalCount / pageSize);
    }

    public PageResult(List<T> data, Long pageNo, Long pageSize, Long totalCount) {
        this.data = data;
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.totalPage = (int) Math.ceil((double) totalCount / pageSize);
    }

}